﻿function handleDashboardChartSize(chartIDlike, gridIDlike, isWidgetViewPage) {
    
    // below line added by 'Imran Gani' on 20-Dec-2012, to make the dashboards UI with better alignment.
    if (isWidgetViewPage) {
        $("td[id^=td_WidgetChart_] span:first-child").css("display", "block").css("overflow", "hidden");
        $("div[id^=" + gridIDlike + "] td").css("overflow", "hidden");
    }
    else {
        $("td[id^=ctl00_ContentPlaceHolder3_td_WidgetChart_] span:first-child").css("display", "block").css("overflow", "hidden");
        $("div[id^=" + gridIDlike + "] td").css("overflow", "hidden");
    }

    $("img[id^=" + chartIDlike + "]").each(function () {
        if (isWidgetViewPage) {
            chartResize(100, this, true);
            $("#tabs").width($(this).width() + 40);
        }
        else
            chartResize(67, this, true);
    });

    $("div[id^=" + chartIDlike + "]").each(function () {
        if (isWidgetViewPage) {
            chartResize(100, this, true);
            $("#tabs").width($(this).width() + 40);
        }
        else {
            chartResize(75, this, true);
            $(this).height($(this).height() + 25)
        }
    });

    if (isWidgetViewPage) {
        $("[id^=" + gridIDlike + "]").each(function () {
            if ($(this).prop("tagName").toLowerCase() != "div") {
                chartResize(95, this, false);
                $("#tabs").width(screen.width - 50);
            }
        });
    }
    else {
        $("[id^=" + gridIDlike + "]").each(function () {
            if ($(this).prop("tagName").toLowerCase() != "div") {
                if ($(this).height() > 300)
                    chartResize(67, this, true);
                else 
                        chartResize(67, this, false);
            }
        });
    }
}

function chartResize(reduceSize, obj, isHeight) {
    var chartWidth = $(obj).width();
    var clientWidth = screen.width - reduceSize;
    var serverWidth = 1600;
    $(obj).width(Math.floor(chartWidth * (clientWidth / serverWidth)));

    if (isHeight) {
        var chartHeight = $(obj).height();
        var clientHeight = screen.height;
        var serverHeight = 900;
        $(obj).height(Math.floor(chartHeight * (clientHeight / serverHeight)));
    }
}